package org.linlinjava.litemall.brand.service;

import org.linlinjava.litemall.db.dao.LitemallBrandAppendMapper;
import org.linlinjava.litemall.db.domain.LitemallBrandAppend;
import org.linlinjava.litemall.db.domain.LitemallBrandAppendExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class BrandFigureService {
    @Resource
    private LitemallBrandAppendMapper brandAppendMapper;

    public List<LitemallBrandAppend> findByBrandId(Integer brandId) {
        LitemallBrandAppendExample example = new LitemallBrandAppendExample();
        example.or().andAppendTypeEqualTo("staff").andBrandIdEqualTo(brandId);
        return brandAppendMapper.selectByExample(example);
    }

    public void add(LitemallBrandAppend litemallBrandAppend) {
        brandAppendMapper.insertSelective(litemallBrandAppend);
    }

    public void update(LitemallBrandAppend litemallBrandAppend) {
        brandAppendMapper.updateByPrimaryKeySelective(litemallBrandAppend);
    }

    public void delete(Integer id) {
        brandAppendMapper.deleteByPrimaryKey(id);
    }

    public List<LitemallBrandAppend> findByBrandIdPic(Integer brandId) {
        List<String> list = new ArrayList<>();
        Collections.addAll(list,"home_page","profile","qualify","figure","contact","goods");
        LitemallBrandAppendExample example = new LitemallBrandAppendExample();
        example.or().andAppendTypeIn(list).andBrandIdEqualTo(brandId);
        return brandAppendMapper.selectByExample(example);
    }

    public void addPic(LitemallBrandAppend litemallBrandAppend) {
        brandAppendMapper.insertSelective(litemallBrandAppend);
    }

    public void updatePic(LitemallBrandAppend litemallBrandAppend) {
        brandAppendMapper.updateByPrimaryKeySelective(litemallBrandAppend);
    }

    public void deletePic(Integer id) {
        brandAppendMapper.deleteByPrimaryKey(id);
    }
}
